import EventEmitter from "./EventEmitter.js";
export default class Time extends EventEmitter {
    constructor(){
        super();

        this.start = performance.now();
        this.current = this.start;
        this.elapsed = 0;
        this.delta = 16;
        this.tick();//执行动画

    }

    tick(){
        
        const currentTime = performance.now();
        this.delta = currentTime - this.current;
        this.current = currentTime;
        this.elapsed = this.elapsed - this.start;
        this.trigger("tick");
        
        requestAnimationFrame(()=>this.tick());
    }
    
}